import Vue from 'vue'
import App from './App.vue'
import router from './router'
import axios from "axios";
// 引入 ui 库
import ElementUI from 'element-ui';

// 绑定到原型
Vue.prototype.$axios = axios;
Vue.config.productionTip = false

// ui 库引入 css
import 'element-ui/lib/theme-chalk/index.css';
//注册组件库
Vue.use(ElementUI);
// 引入富文本
import vueEditor from 'vue-editor-interline'
import 'vue-editor-interline/lib/vue-editor-interline.css'

Vue.use(vueEditor)
// 设置基准路径
axios.defaults.baseURL = 'http://liangwei.tech:3000'
// 拦截器
axios.interceptors.request.use(config => {
  if (!config.headers.Authorization && localStorage.getItem("token")) {
    config.headers.Authorization = localStorage.getItem("token")
  }
  return config
})

// 过滤器
Vue.filter('fixImgUrl', (oldUrl) => {
  if (oldUrl.indexOf('http') > -1) {
    return oldUrl
  } else {
    return axios.defaults.baseURL + oldUrl
  }
})
new Vue({
  router,
  render: function (h) { return h(App) }
}).$mount('#app')
